var API = {
    // DOMAIN: window.location.href.startsWith("https://rado-h5.omnimkt.com/") ? "https://rado-h5.omnimkt.com/rado" : "http://192.168.0.222:8991",               //正式
    DOMAIN: window.location.href.startsWith("https://rado-h5.omnimkt.com/") ? "https://rado-h5.omnimkt.com/rado" : "http://192.168.0.222:8991",               //正式
    DEBUG: true,

    _send: function (method, data, success, type = "POST") {
        //有自己的openid并且data里面不带openid才赋值
        // if (API.OpenID && !data.hasOwnProperty('OpenID'))data.OpenID = API.OpenID;

        $.ajax({
            url: API.DOMAIN + method,
            type: type,
            data: data,
            dataType: 'json',
            headers: {
                'Authorization': 'Bearer ' + window.localStorage.getItem('token')
            },
            timeout: 1000,
            //async: true,
            success: function (res) {
                if (API.DEBUG) {
                    console.log(method + "——success");
                    console.log(res);
                }

                if (res && res.code == 200) {
                    if (success) success(res);
                } else {
                    icom.alert(res.msg, function () {
                        if (res.code == 403 || res.code == 401) {
                            window.localStorage.clear();
                            window.location.replace("https://rado-h5.omnimkt.com/html/rado/tanabata/index.html");
                        }
                        if (success) success(res);
                    })

                }

            },
            error: function (res) {
                if (API.DEBUG) {
                    console.log(method + "——fail");
                    console.log(res);
                }
                if (success) success(null);

                icom.alert("网络超时", function () {
                    window.location.replace("https://rado-h5.omnimkt.com/html/rado/tanabata/index.html");
                })

            },
            complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
                // if (status == 'timeout') {//超时,status还有success,error等值的情况
                //     alert("超时");
                // }
            }
        });

    },


    /**
     * @params String backurl 回调URL 需要URL编码 不传默认index.html页面
     * @params Function success 回调函数 如果回调为null说明服务器报错了或者errcod非0
     */
    // Login: function (backurl, success) {
    //     API._send('Login', { backurl: backurl }, success);
    // },
    // 授权注册
    userRegister: function (data, success) {
        API._send('/rado/userRegister', data, success);
    },

    // 发送弹幕
    userSendBarrage: function (data, success) {
        API._send('/rado/userSendBarrage', data, success);
    },

    // 发短信
    smsSend: function (data, success) {
        API._send('/sms/send', data, success, "GET");
    },

    // 用户登记
    userInfoRegister: function (data, success) {
        API._send('/rado/userInfoRegister', data, success);
    },

    // 用户信息回显
    getUserInfo: function (data, success) {
        API._send('/rado/getUserInfo', data, success, "GET");
    },

    // 用户弹幕列表
    userBarrageList: function (data, success) {
        API._send('/rado/userBarrageList', data, success, "GET");
    },

    // 用户表白人数
    confessionTimes: function (data, success) {
        API._send('/rado/confession/times', data, success, "GET");
    },

    // 店铺列表 经纬度
    shopList: function (data, success) {
        API._send('/rado/shop/list', data, success, "GET");
    },

    // 根据城市查店铺
    listCity: function (data, success) {
        API._send('/rado/shop/list/city', data, success, "GET");
    },

    // 用户绑定店铺
    bindingAddress: function (data, success) {
        API._send('/rado/user/binding/address', data, success);
    },

    // 预约状态
    subscribeStatus: function (data, success) {
        API._send('/rado/subscribe/status', data, success, "GET");
    },

    // 根据手机号查询预约信息
    subscribeInfoMobile: function (data, success) {
        API._send('/rado/subscribe/info/mobile', data, success, "GET");
    },

    // 预约时间比较 天猫
    subscribeTimTm: function (data, success) {
        API._send('/rado/subscribe/tm/time', data, success, "GET");
    },

    // 预约时间比较 京东
    subscribeTimJd: function (data, success) {
        API._send('/rado/subscribe/jd/time', data, success, "GET");
    },

    // 查询名字
    userOpenId: function (data, success) {
        API._send('/rado/user/openId', data, success, "GET");
    },

}
